package ru.nnstu.medialib.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;

import ru.nnstu.medialib.domain.Artist;
import ru.nnstu.medialib.domain.Song;

public class SongDAOImpl implements SongDAO {

	@Override
	public void saveSong(Song song) {
		Session session = HibernateUtil.getSession();
		Transaction tr = session.beginTransaction();
		session.save(song);
		tr.commit();
	}

	@Override
	public List<Song> listSong() {
		Session session = HibernateUtil.getSession();
		Criteria crit = session.createCriteria(Song.class);
		return crit.list();
	}

	@Override
	public void removeSong(Long id) {
		Session session = HibernateUtil.getSession();
		Object obj = session.load(Song.class, id);
		session.delete(obj);
	}

}
